package cn.tpshion.vm.controller;

import cn.tpshion.vm.common.model.Result;
import cn.tpshion.vm.domain.dto.secret.AddSecretDTO;
import cn.tpshion.vm.domain.vo.SecretVO;
import cn.tpshion.vm.service.SecretService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/secret")
public class SecretController {

    @Resource
    private SecretService secretService;

    @PostMapping("/addSecret")
    public Result addSecret(@Valid @RequestBody AddSecretDTO dto){
        secretService.addSecret(dto);
        return Result.ok();
    }

    @DeleteMapping("deleteSecret")
    public Result deleteSecret(@RequestParam String type, @RequestParam String name){
        secretService.deleteSecret(type, name);
        return Result.ok();
    }

    @GetMapping("/getSecretList")
    public Result<List<SecretVO>> getSecretList(@RequestParam(required = false) String type){
        return Result.ok(secretService.getSecretList(type));
    }
}
